package com.kim.bookshop.litener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


@WebListener
public class SpringServletContextListener implements ServletContextListener {

   
    public SpringServletContextListener() {
        // TODO Auto-generated constructor stub
    }

	//当服务器加载得时候执行
    public void contextInitialized(ServletContextEvent arg0) {
    	ServletContext servletContext=arg0.getServletContext();//获取ServletContext对象
    	String config=servletContext.getInitParameter("contextConfigLocation");//获取初始化参数
    	ApplicationContext ctx=new ClassPathXmlApplicationContext(config);//创建IOC容器
    	servletContext.setAttribute("ApplicationContext", ctx);//保存到application中
    }

	
    public void contextDestroyed(ServletContextEvent arg0) {
    }
	
}
